/**
 *
 * @title       base.js
 * @author      ld
 * @date        2011-07-21
 * @version     1.0.1
 * @version     1.0.2 加强on函数的功能，增加scope参数，用于设置handler中的this指针指向，默认指向node节点
 * @description base js
 *
 */
var GLOBAL = {};
/**
 * @title       命名空间
 * @argument    str == 空间名字
 */
GLOBAL.namespace = function (str){
    var arr = str.split(".");
    var o = GLOBAL;
    for ( var i = (arr[0] == "GLOBAL") ? 1 : 0 ; i < arr.length ; i++ ){
        o[arr[i]] = o[arr[i]] || {};
        o = o[arr[i]];
    }
};
/**
 * @title       DOM相关=================================================================================================
 * @description 兼容IE跟FF
 */
GLOBAL.namespace("Dom");
/**
 * @title       getNextNode
 * @argument    node == 节点id
 */
GLOBAL.Dom.getNextNode = function (node){
    node = typeof node == "string" ? document.getElementById(node) : node;
    var nextNode = node.nextSibling;
    if( !nextNode ) return null;
    if( !document.all ){
        while(true){
            if( nextNode.nodeType == 1 ){
                break;
            } else {
                if( nextNode.nextSibling ){
                    nextNode = nextNode.nextSibling;
                } else {
                    break;
                }
            }
        }
    }
    return nextNode;
};
/**
 * @title       setOpacity
 * @argument    node == 节点id, level == 透明度
 */
GLOBAL.Dom.setOpacity = function (node,level) {
    node = typeof node == "string" ? document.getElementById(node) : node;
    if(document.all){
        node.style.filter = 'alpha(opacity=' + level + ')';
    } else {
        node.style.opacity = level / 100;
    }
};
/**
 * @title       get
 * @argument    node == 节点id
 */
GLOBAL.Dom.get = function (node) {
    node = typeof node == "string" ? document.getElementById(node) : node;
    return node;
};
/**
 * @title       getElementsByClassName
 * @argument    str class名, root 根节点id , tag 标签名
 */
GLOBAL.Dom.getElementsByClassName = function (str,root,tag) {
    if( root ){
        root = typeof root == "string" ? document.getElementById(root) : root;
    } else {
        root = document.body;
    }
    tag = tag || "*";
    var els = root.getElementsByTagName(tag);
    var arr[];
    for( var i = 0 , n = els.length ; i < n ; i++ ){
        for(var j = 0 , k = els[i].className.split(" ") , l = k.length ; j < l ; j++ ){
            if( k[j] == str ){
                arr.push(els[i]);
                break;
            }
        }
    }
    return arr;
};
/**
 * @title       Event相关==============================================================================
 * @description 兼容IE跟FF
 */
GLOBAL.namespace("Event");
/**
 * @title       getEventTarget
 * @argument    e == event
 */
GLOBAL.Event.getEventTarget = function (e) {
    e = window.event || e;
    return e.srcElement || e.target;
};
/**
 * @title       stopPropagation
 * @argument    e == event
 */
GLOBAL.Event.stopPropagation = function (e) {
    e = window.event || e;
    if( document.all ){
        e.cancelBubble = true;
    } else {
        e.stopPropagation();
    }
};
/**
 * @title       on
 * @argument    node == 节点id , eventType == 事件类型 ，handler == 处理过程
 */
GLOBAL.Event.on = function (node,eventType,handler,scope) {
    node = typeof node == "string" ? document.getElementById(node) : node;
    scope = scope || node;
    if( document.all ){
        node.attachEvent("on" + eventType ,function() {handler.apply(scope,arguments)});
    } else {
        node.addEventListener(eventType,function() {handler.apply(scope,arguments)},false);
    }
};
/**
 * @title       Lang相关==============================================================================
 * @description 一些常用函数
 */
GLOBAL.namespace("Lang");
/**
 * @title       trim
 * @argument    ostr == 待处理的字符串
 */
GLOBAL.Lang.trim = function (ostr) {
    return ostr.replace(/^\s+|\s+$/g,"");
};
/**
 * @title       isNumber
 */
GLOBAL.Lang.isNumber = function (s) {
    return !isNaN(s);
};
/**
 * @title       isString
 */
GLOBAL.Lang.isString = function (s) {
    return typeof s === "string";
}
/**
 * @title       extend
 * @argument    subClass == 子类名，superClass == 父类名
 */
GLOBAL.Lang.extend = function (subClass,superClass) {
    var F = function() {};
    F.prototype = superClass.prototype;
    subClass.prototype = new F();
    subClass.prototype.constructor = subClass;
    subClass.superclass = superClass.prototype;
    if( superClass.prototype.constructor == Object.prototype.constructor ){
        superClass.prototype.constructor = superClass;
    }
};
